﻿using Grpc.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using RabbitMQ.Client;
using System.Text;
using Newtonsoft.Json;
using Microsoft.Extensions.Options;
using ZYHand.Entity;
using Microsoft.Extensions.Configuration;
using ZYHand.Repository;
using ZYHand.IService;
using RabbitMQ.Client.Events;
using Nest;
using ZYHand.IRepository;

namespace ZYHand.Service
{
    public class RabbitMQService : IRabbitMQService
    {
        public RabbitMQService()
        {
           
        }


        //
        /// <summary>
        /// 接收数据后，插入到MQ中
        /// </summary>
        /// <param name="queue"></param>
        /// <param name="exchange"></param>
        /// <param name="routingkey"></param>
        /// <param name="data">json数据</param>
        /// <returns></returns>
        public bool Publish(string queue, string exchange, string routingkey, string data)
        {
            IRabbitMQRepository rabbitMQRepository = new RabbitMQRepository();
            //2.插入MQ
            if (!string.IsNullOrEmpty(data)) //如果客户端传过来的订单数据不为空
            {
                byte[] buffer = Encoding.UTF8.GetBytes(data);
                if (rabbitMQRepository.Publish(queue, exchange, routingkey, buffer))
                {
                    return true;
                }
            }
            return false;
        }
    }
}
